package com.jackiechan.day16;

public class SYN_Thread {
    public static void main(String[] args) {
        Mythread mythread = new Mythread();
        Thread t0 = new Thread(mythread,"赵");
        Thread t1 = new Thread(mythread,"钱");
        Thread t2 = new Thread(mythread,"孙");
        Thread t3 = new Thread(mythread,"李");
        t0.start();
        t1.start();
        t2.start();
        t3.start();
    }

    static class Mythread extends Thread{
        int count = 100;
//        double start = 0;
//        double end = 0;

        @Override
        public void run() {
//            start = System.nanoTime();
            while (true){
                synchronized (Mythread.class){
                    if (count>0){
                        System.out.println(Thread.currentThread().getName()+" 为您服务: 卖出"+(100-count+1)+"号票,余票"+(--count));
                    }else {
                        System.out.println(Thread.currentThread().getName()+" 为您服务: 已售罄");
                        break;
                    }
                }
            }
//            end = System.nanoTime();
//            System.out.println(Thread.currentThread().getName()+" 已工作时长:"+(end - start)/1000000+"毫秒");
        }
    }
}
